package cn.yunxiang.summer.framework.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author wangqx
 * @description TODO
 * @date 2022/6/16
 */
@RequiredArgsConstructor
@Data
public class BusinessImpl<S extends IService<T>, C extends BaseConverter<V,D,T>,V,D,T> implements IBusiness<V, D> {
    protected final S service;

    protected final C converter;

    @Override
    public boolean save(D dto) {
        T t=converter.convertToPo(dto);
        return service.save(t);
    }

    @Override
    public V get(Serializable id) {
        T t= service.getById(id);
        return converter.convertToVO(t);
    }

    @Override
    public List<V> list(D d) {
        List<T> tList=service.list();

        return converter.convertToVO(tList);
    }

    @Override
    public IPage<V> page(IPage<V> page,D d) {

        IPage<T> tiPage=new Page<>();
        tiPage.setCurrent(page.getCurrent());
        tiPage.setSize(page.getSize());
        tiPage=service.page(tiPage);

        return converter.convertToVO(tiPage);
    }

    @Override
    public boolean delete(Serializable id) {
        service.removeById(id);
        return true;
    }


}
